package com.mall.autoconfig.exception;

import com.mall.model.vo.CommonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author : xyiaao
 * @createDate : 2022/3/18 10:29
 * @CrossOrigin@RestControllerAdvice : 方法以json形式返回
 */
@Slf4j
@RestControllerAdvice
public class ExceptionAdvice {

    @ExceptionHandler(BusinessException.class)
    public CommonResult handlerException(BusinessException businessException) {

        log.error(businessException.getMessage());
        businessException.printStackTrace();
        return CommonResult.error(businessException.getMessage());
    }


    @ExceptionHandler(Exception.class)
    public CommonResult handlerException(Exception exception) {

        log.error(exception.getMessage());
        exception.printStackTrace();
        return CommonResult.error("系统繁忙中，请稍后再试");
    }

}
